// @ts-ignore
/* eslint-disable */
import { request } from '@umijs/max';
const apiPrefix = '/web';

/** 获取用户信息(包括租户站点) GET /user/profile */
export async function sysProfileControllerProfile(options?: { [key: string]: any }) {
  return request<API.ApiResultUserProfileVo>(`${apiPrefix}/user/profile`, {
    method: 'GET',
    ...(options || {}),
  });
}

/** 个人资料修改 PUT /user/profile */
export async function sysProfileControllerUpdateProfile(
  body: API.UserInfoForm,
  options?: { [key: string]: any },
) {
  return request<API.ApiResultObject>(`${apiPrefix}/user/profile`, {
    method: 'PUT',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 上传头像 POST /user/profile/avatar */
export async function sysProfileControllerAvatar(
  body: {},
  attr?: File,
  options?: { [key: string]: any },
) {
  const formData = new FormData();

  if (attr) {
    formData.append('attr', attr);
  }

  Object.keys(body).forEach((ele) => {
    const item = (body as any)[ele];

    if (item !== undefined && item !== null) {
      if (typeof item === 'object' && !(item instanceof File)) {
        if (item instanceof Array) {
          item.forEach((f) => formData.append(ele, f || ''));
        } else {
          formData.append(ele, JSON.stringify(item));
        }
      } else {
        formData.append(ele, item);
      }
    }
  });

  return request<API.ApiResultObject>(`${apiPrefix}/user/profile/avatar`, {
    method: 'POST',
    data: formData,
    requestType: 'form',
    ...(options || {}),
  });
}

/** 修改密码 PUT /user/profile/password */
export async function sysProfileControllerResetPwd(
  body: API.PasswordForm,
  options?: { [key: string]: any },
) {
  return request<API.ApiResultObject>(`${apiPrefix}/user/profile/password`, {
    method: 'PUT',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}
